/**
 * Created by OneDream on 2016/1/12.
 */
var counts;
var xmlHttpRequest=null;
var len=0;
self.addEventListener("message",function(e){
    //postMessage(e.data);
    counts=e.data;
    start();
});

function start(){

    var url = "http://192.168.1.11:8080/WeiXin/getMessageLog"+counts;
    //1.创建XMLHttpRequest组建
    if(xmlHttpRequest!=null){
    //2.设置回调函数
    xmlHttpRequest.onreadystatechange = callback;

    //3.初始化XMLHttpRequest组建
    xmlHttpRequest.open("GET",url,true);

    //4.发送请求
    xmlHttpRequest.send();
    }else{
        xmlHttpRequest=new XMLHttpRequest();
        xmlHttpRequest.onreadystatechange = callback;

        //3.初始化XMLHttpRequest组建
        xmlHttpRequest.open("GET",url,true);

        //4.发送请求
        xmlHttpRequest.send();
    }
   setTimeout(start,3000);
}


//回调函数
function callback(){
    if(xmlHttpRequest.readyState == 4){
        if( xmlHttpRequest.status == 200){
        var b = xmlHttpRequest.responseText;
            //postMessage(b);
            var data=JSON.parse(b);
            if(data.data.length!=len){
                len=data.data.length;
                self.postMessage(data.data);
            }
        }
    }
}

